<?php 
$v_worktype_id = _replace_bad_char(trim($_REQUEST['txt_code'])) ;

$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter=_replace_bad_char(trim($_REQUEST['hdn_filter']));
}	
//Lay danh sach id cua can bo duoc cap nhat tien do khi giai quyet mot loai ho so
$v_staff_id_list = "";
if(isset($_REQUEST['hdn_staff_id_list'])){
	$v_staff_id_list = trim($_REQUEST['hdn_staff_id_list']);
}	

$v_url = "/list/worktype/index.php?modal_dialog_mode=1" . "&hdn_worktype_id=" . $v_worktype_id . "&fuseaction=DISPLAY_SINGLE_WORKTYPE" ;
// Kiem tra xem nguoi dang nhap hien thoi co quyen cap nhat hay khong?
if(!_check_permission_on_function($_SESSION['staff_id'], $_ISA_APP_CODE, _CONST_ONEGATE_WORKTYPE_UPDATE)){?>
	<script>
		alert("<? echo _CONST_FUNCTION_PERMISSION_ERROR; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<? echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?
}

$v_old_worktype_id = _replace_bad_char(trim($_REQUEST['hdn_item_id']));
$v_code = _replace_bad_char(trim($_REQUEST['txt_code']));
$v_name = _replace_bad_char($_REQUEST['txt_name']);
$v_order = intval($_REQUEST['txt_order']);
if ($v_order==""){
	$v_order = NULL;
}
$v_status = $_REQUEST['hdn_worktype_status'];
$v_occuring_time = $_REQUEST['sel_process_step'];
$v_occuring_number= intval($_REQUEST['sel_occuring_number']);

$v_record_status = $_REQUEST['sel_status'];
$v_recordtype_id_list = trim($_REQUEST['hdn_recordtype_id_list']);
$v_number_id_list = trim($_REQUEST['hdn_number_id_list']);				// nieuvv-180608


$v_delimitor = _CONST_LIST_DELIMITOR;
$v_deleted_exist_file_id_list = $_REQUEST['hdn_deleted_exist_file_id_list']; //Danh sach cac id file da ton tai bi xoa
$v_deleted_new_file_id_list = $_REQUEST['hdn_deleted_new_file_id_list'];  //Danh sach cac id file them moi da bi xoa
//echo 'v_deleted_exist_file_id_list'.$v_deleted_exist_file_id_list.'<br>'; 
//echo 'v_deleted_new_file_id_list'.$v_deleted_new_file_id_list.'<br>'; ;
$v_new_file_id = 0;
$v_new_file_id_list = "";

if(_is_sqlserver()){
	for($v_index=0; $v_index<_CONST_MAX_NUMBER_ATTACH_FILE; $v_index++){
		$v_form_field = 'file_attach_worktype'.$v_index;	
		if (isset($_FILES[$v_form_field]['tmp_name'])){
			// Neu file nay khong thuoc danh sach file da bi xoa			
			if ($v_deleted_new_file_id_list=="" Or _list_have_element($v_deleted_new_file_id_list, $v_index, ",")==false){
				$v_filename = _replace_bad_char(trim($_FILES[$v_form_field]['name']));
				$v_tmp_filename = $_FILES[$v_form_field]['tmp_name'];
				$v_file_id = 0;
				if ($v_tmp_filename!="" and !is_null($v_tmp_filename)){
					_copy_file($v_tmp_filename, _CONST_LEVEL2_UPLOAD_IMAGE_PATH_FROM_CURRENT.$v_filename);
					if ($v_new_file_id_list ==""){
						$v_new_file_id_list = _save_file_to_database('T_TEMP_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT', _CONST_LEVEL2_UPLOAD_IMAGE_PATH_FROM_CURRENT.$v_filename);
					}else{			
						$v_new_file_id_list = $v_new_file_id_list . ",". _save_file_to_database('T_TEMP_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT', _CONST_LEVEL2_UPLOAD_IMAGE_PATH_FROM_CURRENT.$v_filename);
					}	 
				}	
			}	
		}	
	}
	
	$sql = "Exec ONEGATE_WorktypeUpdate ";
	$sql = $sql . "'".$v_worktype_id."'";
	$sql = $sql . ",'".$v_old_worktype_id."'";
	$sql = $sql . ",'".$v_name."'" ;
	$sql = $sql . ",".$v_order;
	$sql = $sql . ",".$v_status;
	$sql = $sql . ",'".$v_occuring_time."'";
	$sql = $sql . ",".$v_occuring_number;
	$sql = $sql . ",'".$v_record_status."'";
	$sql = $sql . ",'".$v_recordtype_id_list."'";
		$sql = $sql . ",'".$v_number_id_list."'";			// nieuvv
	$sql = $sql . ",'".$v_delimitor."'";
	$sql = $sql . ",'" . $v_new_file_id_list . "'" ;
	$sql = $sql . ",'" . $v_deleted_exist_file_id_list . "'" ;	
	$sql = $sql . ",'" . $v_staff_id_list . "'" ;	
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
}

if (!is_null($v_error) and $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
sleep(0);
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_ALL_WORKTYPE">
	<input type="hidden" name="hdn_item_id" value="<?php echo $v_old_worktype_id;?>">
	<input type="hidden" name="hdn_filter" value="<?php echo $v_filter; ?>">
</form>
<Script language="javascript">
	return_value = "<?php echo $v_worktype_id; ?>" + _LIST_DELIMITOR + "<?php echo $v_filter; ?>"  
	goto_after_update_data(0, "DISPLAY_SINGLE_WORKTYPE",return_value);
//	document.forms(0).submit();
</Script>
